<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/admin-header::header">
    <title>用户设置</title>
</head>


<body class="app sidebar-mini rtl">

<div th:replace="common/admin-sadbar::sadbar"></div>

<main class="app-content">
    <div class="row user">
        <!--<div class="col-md-12">-->
        <!--<div class="profile">-->
        <!--<div class="info"><img class="user-img" th:src="@{/static/valires/img/my.jpg}">-->
        <!--<h4 th:text="">John Doe</h4>-->
        <!--<p>Test Developer</p>-->
        <!--</div>-->
        <!--<div class="cover-image"></div>-->
        <!--</div>-->
        <!--</div>-->
        <div class="col-md-3">
            <div class="tile p-0">
                <ul class="nav flex-column nav-tabs user-tabs">
                    <li class="nav-item"><a class="nav-link active" href="#user-info" data-toggle="tab">个人信息</a>
                    </li>
                    <li class="nav-item"><a class="nav-link" href="#user-config" data-toggle="tab">设置</a></li>
                    <li class="nav-item"><a class="nav-link" href="#security-settings" data-toggle="tab">安全</a></li>
                </ul>
            </div>
        </div>
        <div class="col-md-9">
            <div class="tab-content">
                <div class="tab-pane active" id="user-info">
                    <div class="timeline-post">
                        <div class="post-media">
                            <img th:src="@{/static/valires/img/my.jpg}">
                            <div class="content">
                                <h5><a href="/" th:text="${user.getNickName()}">Xuedonglei</a></h5>
                                <p class="text-muted"
                                   th:text="${#dates.format(user.getRegistrationTime(),'yyyy-MM-dd HH:mm:ss')}">
                                    <small th:text="${#dates.format(user.getRegistrationTime(),'yyyy-MM-dd HH:mm:ss')}">
                                        2 January at 9:30
                                    </small>
                                </p>
                            </div>
                        </div>
                        <div class="post-content">
                            <form class="form-horizontal" method="post" th:action="@{/user/user}">
                                <div class="form-group">
                                    <label for="emailinfo" class="col-sm-2 control-label">账号</label>
                                    <div class="col-sm-10">
                                        <input name="email" th:value="${user.getEmail()}" type="email"
                                               class="form-control" id="emailinfo"
                                               th:placeholder="${user.getEmail()}" readonly>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label for="nickname" class="col-sm-2 control-label">昵称</label>
                                    <div class="col-sm-10">
                                        <input name="nickName" type="text" class="form-control" id="nickname"
                                               placeholder="Password" th:value="${user.getNickName()}">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label">注册时间</label>
                                    <div class="col-sm-10">
                                        <input type="text" class="form-control"
                                               th:value="${#dates.format(user.getRegistrationTime(),'yyyy-MM-dd HH:mm:ss')}"
                                               readonly>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label">账号类型</label>
                                    <div th:if="${user.getIsAdmin()} eq true" class="col-sm-10">
                                        <input type="text" class="form-control" th:value="管理员" readonly>
                                    </div>
                                    <div th:if="${user.getIsAdmin()} eq false" class="col-sm-10">
                                        <input type="text" class="form-control" th:value="普通用户" readonly>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="col-sm-offset-2 col-sm-10">
                                        <button type="submit" class="btn btn-primary">更新</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
                <div class="tab-pane" id="user-config">
                    <div class="timeline-post">
                        <div class="post-media">
                            <img th:src="@{/static/valires/img/my.jpg}">
                            <div class="content">
                                <h5><a href="/" th:text="${user.getNickName()}">Ha ha</a></h5>
                                <p class="text-muted">
                                    <small th:text="${#dates.format(user.getRegistrationTime(),'yyyy-MM-dd HH:mm:ss')}">
                                        2 January at 9:30
                                    </small>
                                </p>
                            </div>
                        </div>
                        <div class="post-content">
                            <div class="alert alert-danger" role="alert">一旦删除账号，数据不可恢复，请谨慎操作！</div>
                            <button class="btn btn-danger" onclick="delUser()" type="button">删除用户</button>
                        </div>
                    </div>
                </div>
                <div class="tab-pane" id="security-settings">
                    <div class="timeline-post">
                        <div class="post-content">
                            <form class="form-horizontal" method="post" th:action="@{/user/reset}">
                                <div class="form-group">
                                    <label for="email" class="col-sm-2 control-label">账号</label>
                                    <div class="col-sm-10">

                                        <input name="email" th:value="${user.getEmail()}" type="email"
                                               class="form-control" id="email" th:placeholder="${user.getEmail()}"
                                               readonly>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="oldpwd" class="col-sm-2 control-label">密码</label>
                                    <div class="col-sm-10">
                                        <input name="password" type="password" class="form-control" id="oldpwd"
                                               placeholder="Password">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="newpwd" class="col-sm-2 control-label">新密码</label>
                                    <div class="col-sm-10">
                                        <input name="new_pwd" type="password" class="form-control" id="newpwd"
                                               placeholder="Password">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-offset-2 col-sm-10">
                                        <button type="submit" class="btn btn-primary">更新</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</main>

<div th:include="common/script::script"></div>
<script th:inline="javascript">

    function delUser() {
        var cf = confirm("确认是否删除用户？")
        if (cf) {
            $.ajax({
                type: 'DELETE',
                url: '/flytest/user/user?' + 'email=' + [[${session.email}]],
                success: function (result) {
                    console.log(result);
                    if (result.msg !== 'false') {
                        swal({
                            title: "删除成功！",
                            text: "已成功注销账号",
                            type: "success"
                        });
                        window.location.href = '/flytest/user/login'
                    }
                }
            })
        }
    }
</script>
</body>
</html>